import { defineStore } from 'pinia'
import { SetupStoreId } from '@/enum'
import { merge } from 'lodash'
import { ref } from 'vue'

export const useProductStore = defineStore(SetupStoreId.Product, () => {
  // 更新商品规格参数
  const specificationData = ref<Api.Product.GoodsUpdateSkusParams>({
    id: 0,
    sku_type: 0,
    sku_value: {
      oprice: 0,
      pprice: 0,
      cprice: 0,
      weight: 0,
      volume: 0,
    },
    goodsSkus: [
      {
        code: '',
        cprice: '0.00',
        goods_id: 0,
        id: 0,
        image: '',
        oprice: '0.00',
        pprice: '0.00',
        skus: [
          {
            goods_skus_card_id: '',
            name: '',
            order: 0,
            value: '',
            id: '',
            text: '',
          },
        ],
        stock: 0,
        volume: 0,
        weight: 0,
      },
    ],
  })

  const updateSpecificationData = (data: Api.Product.GoodsUpdateSkusParams) => {
    // 对两个对象进行合并
    specificationData.value = merge(specificationData.value, data)
  }

  return {
    specificationData,
    updateSpecificationData,
  }
})
